/**
 * MassLooper
 *
 * @author		Allen Chou
 * @version		1.0.0 (last update: Aug 5 2008)
 * @link		http://cjcat2266.deviantart.com
 */

package idv.cjcat.utils.framelooper {
	import flash.errors.IllegalOperationError;
	
	import idv.cjcat.CJUtils;
	
	public class MassLooper {
		
		private var _loopers:Array = new Array();
		
		public function MassLooper(loopers:Array = null) {
			if (loopers != null) {
				for (var i:int = 0; i < loopers.length; i++) add(loopers[i]);
			}
		}
		
		public function add(looper:FrameLooper):void {
			if (looper == null) throw new IllegalOperationError("The looper parameter must not be null.");
			CJUtils.addUniqueElement(_loopers, looper);
		}
		
		public function remove(looper:FrameLooper):void {
			CJUtils.removeUniqueElement(_loopers, looper);
		}
		
		public function clear():void {
			_loopers = new Array();
		}
		
		public function step(value:Number = 1):void {
			for (var i:int = 0; i < _loopers.length; i++) _loopers[i].step(value);
		}
	}
}